//
//  MyButton.m
//  03-17-hitTest2Demo
//
//  Created by student on 16/3/17.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "MyButton.h"

@implementation MyButton
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    //判断一下触摸点是不是在button范围内
    CGPoint buttonPoint=[self convertPoint:point toView:self.button];
    if ([self.button pointInside:buttonPoint withEvent:event]) {
        return self.button;
    }
    else
    {
        return [super hitTest:point withEvent:event];
    }
}
//方法3
-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    UITouch *touch=[touches anyObject];
    
    //当前视图中的触摸点
    CGPoint curPoint=[touch locationInView:self];
    //上次的点
    CGPoint perPoint=[touch previousLocationInView:self];
    //偏移量
    
    CGFloat offsetX=curPoint.x-perPoint.x;
    CGFloat offsetY=curPoint.y-perPoint.y;
    
    self.center=CGPointMake(self.center.x+offsetX, self.center.y+offsetY);
    
}

@end
